package com.ncmmall.api.security.interceptor;

import cn.hutool.core.util.StrUtil;
import com.feijin.commons.lang.PropertiesHelps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;


/**
 * 权限路径配置器
 *
 * @author linxs
 */
@Component
public class WebConfigurer extends WebMvcConfigurationSupport {

    @Autowired
    private AuthorizationInterceptor authorizationInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        String content = PropertiesHelps.getValue("api-access-anon");
        List<String> paths = StrUtil.splitTrim(content, ";");

        paths.add("/wechat/**/*");

        paths.add("/distribution/info");
        paths.add("/distribution/goodsList");
        paths.add("/distribution/channels");

        //腾讯云录制事件回调
        paths.add("/live/session/record/callback");

        //游客直播分类 直播列表
        paths.add("/live/channel/list");
        paths.add("/live/list");
        paths.add("/live/login");

        //支付回调
        paths.add("/wechat/pay/alipay/**/callback");
        paths.add("/wechat/pay/app/**/callback");

        String[] anons = new String[paths.size()];
        paths.toArray(anons);

        registry.addInterceptor(authorizationInterceptor).addPathPatterns("/*", "/**/*").excludePathPatterns(anons);
    }

}
